#ifndef _BSP_IIC_H_
#define _BSP_IIC_H_
#include "stm32g0xx_hal.h"

#define IIC_SDA_PORT					GPIOB
#define IIC_SDA_PIN						GPIO_PIN_4
#define IIC_SDA_HIGH()					HAL_GPIO_WritePin(IIC_SDA_PORT, IIC_SDA_PIN, GPIO_PIN_SET)
#define IIC_SDA_LOW()					HAL_GPIO_WritePin(IIC_SDA_PORT, IIC_SDA_PIN, GPIO_PIN_RESET)
#define IIC_SDA_READ()					(HAL_GPIO_ReadPin(IIC_SDA_PORT, IIC_SDA_PIN)==GPIO_PIN_RESET?0:1)

#define IIC_SCL_PORT					GPIOB
#define IIC_SCL_PIN						GPIO_PIN_5
#define IIC_SCL_HIGH()					HAL_GPIO_WritePin(IIC_SCL_PORT, IIC_SCL_PIN, GPIO_PIN_SET)
#define IIC_SCL_LOW()					HAL_GPIO_WritePin(IIC_SCL_PORT, IIC_SCL_PIN, GPIO_PIN_RESET)

#define IIC_NO_ACK						0
#define IIC_ACK							1

#define IIC_DATA_WRITE					0
#define IIC_DATA_READ					1

void bsp_iic_start(void);
void bsp_iic_stop(void);
uint8_t bsp_iic_wait_ack(void);
void bsp_iic_send_byte(uint8_t dat);
void bsp_iic_send_ack(void);
void bsp_iic_send_noack(void);
uint8_t bsp_iic_read_byte(void);
uint8_t bsp_iic_check_dev(uint8_t _addr);

#endif /* _BSP_IIC_H_ */
